<template>
  <div class="ffddsa">
    <div class="boxfvg1" v-for="(item) in DataList" :key="item.id">
      <span class="boxfvg1Ttles">{{ item.name }}</span>
      <div class="progress-barsdff1">
        <transition name="progress-bar-transition">
          <div class="progress-bar-fill" :style="{ width: item.progress + '%', backgroundColor: item.color }">
            <!-- <span class="progress-bar-label">{{ Math.floor(item.progress) }}</span> -->
          </div>
        </transition>
      </div>
      <span class="boxfvg1tootersss">{{ item.value }}%</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      yuanData:[],
      DataList: [],
      colorData: [
        "#5470c6",
        "#91cc75",
        "#fac858",
        "#ee6666",
        "#73c0de",
        "#3ba272",
        "#fc8452",
        "#9a60b4",
      ],
    };
  },
  methods: {
    geSheBelZaiXianLv() {
      this.yuanData.forEach((items, index) => {
          this.DataList.push({
            id: items.id,
            value: items.zaixiannum == null ? 0 : items.zaixiannum / items.zongshu * 100,
            name: items.suozaizhen,
            color: this.colorData[index % this.colorData.length],
            progress: 0,
          });
        });
        this.startProgress();
    },
    startProgress() {
      const totalItems = 100;
      let current = 0;

      const timer = setInterval(() => {
        current++;
        this.DataList.forEach((item) => {
          item.progress = (current * item.value) / totalItems;
        });

        if (current === totalItems) {
          clearInterval(timer);
        }
      }, 1);
    },
  },
};
</script>

<style scoped>
.boxfvg1 {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.boxfvg1 .boxfvg1Ttles {
  width: 130px;
  margin-right: 10px;
  font-size: 16px;
  color: aliceblue;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.boxfvg1 .boxfvg1tootersss {
  width: 74px;
  margin-left: 10px;
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgb(113, 251, 220);
}

.progress-barsdff1 {
  display: inline-block;
  width: 100%;
  height: 16px;
  background-color: rgb(38, 86, 178);
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 8px;
}

.progress-bar-transition-enter-active,
.progress-bar-transition-leave-active {
  transition: width 0.5s;
}

.progress-bar-transition-enter,
.progress-bar-transition-leave-to {
  width: 0;
}

.progress-bar-label {
  position: absolute;
  top: 0;
  right: 8px;
  bottom: 0;
  display: flex;
  align-items: center;
  color: white;
  font-size: 12px;
}
</style>